package com.ruoyi.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.core.domain.entity.GongYingShangUser;
import com.ruoyi.system.mapper.GongYingShangUserMapper;
import com.ruoyi.system.service.IGongYingShangUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 食堂档口供应商信息表 服务实现类
 * </p>
 *
 * @author qubaofeng
 * @since 2025-02-09
 */
@Service
public class GongYingShangUserServiceImpl extends ServiceImpl<GongYingShangUserMapper, GongYingShangUser> implements IGongYingShangUserService {

    @Override
    public List<GongYingShangUser> selectUserList(GongYingShangUser user) {
        return baseMapper.selectUserList(user);
    }

    @Override
    public GongYingShangUser selectUserById(Long userId) {
        return this.baseMapper.selectById(userId);
    }

    @Override
    public boolean haveUserName(GongYingShangUser user) {
        GongYingShangUser dangkouUser = this.baseMapper.selectByUserName(user.getUserName());
        return dangkouUser!=null;
    }

    @Override
    public boolean havePhonenumber(GongYingShangUser user) {
        GongYingShangUser dangkouUser = this.baseMapper.selectByPhone(user.getPhonenumber());
        return dangkouUser!=null;
    }

    @Override
    public int insertUser(GongYingShangUser user) {
        user.setStatus("0");
        int row = baseMapper.insert(user);
        return row;
    }


    @Override
    public int deleteUserByIds(Long[] userIds) {
        for (Long id : userIds){
            GongYingShangUser param = new GongYingShangUser();
            param.setUserId(id);
            param.setDelFlag("2");
            this.baseMapper.updateById(param);
        }
        return 1;
    }

    @Override
    public GongYingShangUser selectUserByName(String username) {
        LambdaQueryWrapper<GongYingShangUser> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(GongYingShangUser::getUserName, username);
        wrapper.eq(GongYingShangUser::getDelFlag, 0);
        return baseMapper.selectOne(wrapper, false);
    }
}
